package com.web;

import com.pojo.User;
import com.service.UserService;
import com.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserService userService;


    @RequestMapping("/users")
    public ResultEntity getUsers() {
        return ResultEntity.ok(userService.All());
    }

    @RequestMapping("/user")
    public ResultEntity user() {
        return ResultEntity.ok(userService.findAll());
    }
    @RequestMapping("/zhuce2")
    public ResultEntity zhuce2(@RequestBody User user) {
        return ResultEntity.ok(userService.insert(user));
    }

    @RequestMapping("/login")
    public ResultEntity Login(@RequestBody User user) {
        userService.login(user.getAccount(), user.getPassword());
       return ResultEntity.ok(userService.login(user.getAccount(), user.getPassword()));
    }

    @RequestMapping("/phone")
    public ResultEntity phone(@RequestBody User user) {
        return ResultEntity.ok(userService.updatephone(user));
    }


    @RequestMapping("/password")
    public ResultEntity password(@RequestBody User user) {
        return ResultEntity.ok(userService.updatepassword(user));
    }

    @RequestMapping("/search")
    public ResultEntity search(User user) {
        return ResultEntity.ok(userService.search(user));
    }

    @RequestMapping("/delete")
    public ResultEntity delete(Integer id) {
        return ResultEntity.ok(userService.delete(id));
    }

    @RequestMapping("/update")
    public ResultEntity update(User user) {
        return ResultEntity.ok(userService.update(user));
    }

    @RequestMapping("/tianjia")
    public ResultEntity tianjia( User user) {
        return ResultEntity.ok(userService.tianjia(user));
    }
}
